#!/usr/bin/env python
# -*- coding:utf-8 -*-


class MemberRewardStrategyObj:
    STRATEGY_STATUS = {
        "INUSE": "STR-001",
        "STOP": "STR-002",
        "RES": "STR-003",
        "DROP": "STR-009"
    }

    ACTION_STR = {
        "STR-001": "登录",
        "STR-002": "注册",
        "STR-003": "日打卡",
    }

    STRATEGY_REWARD_WAY = {
        "STR-001": "积分",
        "STR-002": "红包",
    }

    col_keys = ["id", "name", "create_date", "status", "points", "reward_way", "action", "diff_url"]
    col_def_val = [float(0), "", None, "", float(0), "", "", ""]

    id: float(0)
    name: ""
    create_date: None
    status: ""
    points: 0
    reward_way: ""
    action: ""
    diff_url: ""

    def __init__(self):
        return

    @staticmethod
    def split_params(params):
        import math
        g_param = []
        if params['name'] is not None and len(params['name']) > 0:
            g_param.append('`name`=' + "\'" + str(params['name']) + "\'")
        if params['create_date'] is not None and len(params['create_date']) > 0:
            g_param.append('`create_date`=' + "\'" + params['create_date'] + "\'")
        if params['status'] is not None and len(params['status']) > 0:
            g_param.append('`status`=' + "\'" + params['status'] + "\'")
        if params['points'] is not None and math.fabs(int(params['points'])) > 0:
            g_param.append('`points`=' + "\'" + str(params['points']) + "\'")
        if params['reward_way'] is not None and len(params['reward_way']) > 0:
            g_param.append('`reward_way`=' + "\'" + params['reward_way'] + "\'")
        if params['action'] is not None and len(params['action']) > 0:
            g_param.append('`action`=' + "\'" + params['action'] + "\'")
        if params['diff_url'] is not None and len(params['diff_url']) > 0:
            g_param.append('`diff_url`=' + "\'" + params['diff_url'] + "\'")
        return ', '.join(str(i) for i in g_param)

    @staticmethod
    def concat_datas(g_param):
        from datetime import datetime
        current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        arry = [g_param["name"], current_time, g_param["status"], g_param["points"], g_param["reward_way"],
                g_param["action"], g_param["diff_url"]]
        _res = []
        for _val in arry:
            if isinstance(_val, str):
                _res.append(f"\'{_val}\'")
            else:
                if _val is None:
                    _res.append("null")
                else:
                    _res.append(_val)
        return ', '.join(str(i) for i in _res)

    @staticmethod
    def load_db_2_dict(data):
        g_param = {}
        g_param["id"] = data[0]
        g_param["name"] = data[1]
        g_param["create_date"] = str(data[2])
        g_param["status"] = data[3]
        g_param["points"] = data[4]
        g_param["reward_way"] = data[5]
        g_param["action"] = data[6]
        g_param["diff_url"] = data[7]
        g_param["reward_way_str"] = MemberRewardStrategyObj.STRATEGY_REWARD_WAY[data[5]]
        g_param["action_str"] = MemberRewardStrategyObj.ACTION_STR[data[6]]
        return g_param

    # 标记为true时候，从DBA中读取数据，附带ID主键，标记为false时候忽略自增型字段ID
    @staticmethod
    def to_string(with_flg):
        g_param = []
        if with_flg:
            g_param.append("`mem_member_reward_strategy`.`id`")
            g_param.append("`mem_member_reward_strategy`.`name`")
            g_param.append("`mem_member_reward_strategy`.`create_date`")
            g_param.append("`mem_member_reward_strategy`.`status`")
            g_param.append("`mem_member_reward_strategy`.`points`")
            g_param.append("`mem_member_reward_strategy`.`reward_way`")
            g_param.append("`mem_member_reward_strategy`.`action`")
            g_param.append("`mem_member_reward_strategy`.`diff_url`")
        else:
            g_param.append("`name`")
            g_param.append("`create_date`")
            g_param.append("`status`")
            g_param.append("`points`")
            g_param.append("`reward_way`")
            g_param.append("`action`")
            g_param.append("`diff_url`")
        return ', '.join(str(i) for i in g_param)
